package com.example.admanagement.servlet;

import com.example.admanagement.Ad;
import com.example.admanagement.AdService;
import com.google.gson.Gson;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getAds")
public class GetAdServlet extends HttpServlet {
    private final Gson gson = new Gson();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/json;charset=UTF-8");
        AdService.Result<List<Ad>> result = AdService.getAdsFromDatabase();
        response.getWriter().write(gson.toJson(result));
    }
}